package com.zy.thread.bank3.jiaoti;

/**
 * @Author Gong
 * @Description
 * @dATE 2021/12/14 14:45
 **/
public class PrintNum implements Runnable{
    int num  = 1;
    @Override
    public void run() {
        while(true){
            System.out.println(Thread.currentThread().getName()+"进入线程");
            synchronized(this){
                this.notify();
                if(num <= 100){
                    //此处设置了停顿，给足够多的线程来到这里就绪
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+":"+num);
                    num++;
                }else{
                    break;
                }
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
